package com.bwie.home.backstage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.home.backstage.dao.RankDao;
import com.bwie.home.backstage.entity.CommunityEntity;
import com.bwie.home.backstage.entity.RankEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.bwie.home.backstage.dao.HousingDao;
import com.bwie.home.backstage.entity.HousingEntity;
import com.bwie.home.backstage.service.HousingService;


@Service("housingService")
public class HousingServiceImpl extends ServiceImpl<HousingDao, HousingEntity> implements HousingService {
    @Autowired
    private RankDao rankDao;

    @Autowired
    private HousingDao housingDao;

    @Override
    public IPage<HousingEntity> getList(int page, int limit, String title, int type, CommunityEntity community) {
        Page<HousingEntity> pa = new Page<>(page, limit);
        return housingDao.getList(pa,title,type,community);
    }

    @Override
    public boolean save(HousingEntity entity) {
        RankEntity one = rankDao.selectOne(new QueryWrapper<RankEntity>().eq("community_id", entity.getCommunityId()));
        one.setCommunityNum(one.getCommunityNum()+1);
        rankDao.updateById(one);
        return super.save(entity);
    }
}